<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="#">财务管理</a>
        </li>

        <li>
            <a href="#">提现申请列表</a>
        </li>
    </ul>
    <div>
        <input type="hidden" id="cupage" value="1"/>
        <input type="hidden" id="total" value="1"/>
        <input type="hidden" id="formurl" value="/manager/money/getTxInfoPage"/>
        <input type="hidden" id="startTime" name="startTime" value=""/>
        <input type="hidden" id="endTime" name="endTime" value=""/>
        <input type="hidden" name="user_id" id="user_id"/>
    </div>
</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        筛选条件
                    </h3>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal">
                        <label for="itemName" class="col-sm-1 control-label">产品名称:</label>
                        <div class="col-md-2">
                            <input type="text" class="form-control" id="itemName" placeholder="请输入查询条件">
                        </div>
                        <label for="date1" class="col-sm-1 control-label">申请时间:</label>
                        <div class="col-md-2">
                            <input type="text" name="regular" class="form-control datepicker" id="date1" onBlur="onb()">
                        </div>
                        <label for="status" class="col-sm-1 control-label">是否打款:</label>
                        <div class="col-md-1">
                            <select class="form-control dictSelect" id="status" dict-type="dict_status">
                                <option value="">请选择</option>
                                <option value="0">已打款</option>
                                <option value="1">未打款</option>
                            </select>
                        </div>
                        <div class="col-md-1">
                            <input type="button" id="btn-load" class="btn btn-primary btn-pikaqiu"
                                   data-loading-text="加载中..." value="查 询"/>
                        </div>
                    </form>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        提现列表
                    </h3>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>用户ID</th>
                                <th>用户名称</th>
                                <th>用户手机号</th>
                                <th>提现支付宝</th>
                                <th>提现金额</th>
                                <th>提现前余额</th>
                                <th>提现后余额</th>
                                <th>提现时间</th>
                                <th>操作时间</th>
                                <th>操作人</th>
                                <th>支付宝订单号</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="loadData">

                            </tbody>
                        </table>
                        <!--#include file="/admin/include/page.html"-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="txModal" tabindex="-1" role="dialog" aria-labelledby="txModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">确认打款</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="txForm">
                    <input type="hidden" id="id">
                    <div class="form-group">
                        <label for="userName" class="col-sm-3 control-label">用户姓名</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="userName" disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="phone" class="col-sm-3 control-label">用户手机号</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="phone" disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="alipay" class="col-sm-3 control-label">用户支付宝</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="alipay" disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="money" class="col-sm-3 control-label">提现金额</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="money" disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="alipay_order_id" class="col-sm-3 control-label">转账订单号</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="alipay_order_id" placeholder="转账订单号">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="remark" class="col-sm-3 control-label">备注(失败时填写)</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="remark" placeholder="默认支付宝账号与姓名不匹配">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="txStatus" class="col-sm-3 control-label">是否成功</label>
                        <div class="col-xs-8" id="txStatus">
                            <input name="status" class="ace" value="1" type="radio" checked="checked">
                            <span class="lbl"> 是 </span>
                            <input name="status" class="ace" value="2" type="radio">
                            <span class="lbl"> 否 </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="confirmTx()">确认</button>
            </div>
        </div>
    </div>
</div>

<script>
    $("#btn-load").on("click", function () {
        var a = $(this);
        a.button("loading");
        $("#cupage").val("1");
        loadData();

    });
    initDate();
    function loadData() {
        var para = {
            curPage: $("#cupage").val(),
            itemName: $("#itemName").val(),
            status: $("#status").val(),
            startTime: $("#startTime").val(),
            endTime: $("#endTime").val()
        };
        loadGetServer($("#formurl").val(), para, function (data) {
            var $loadData = $("#loadData");
            $loadData.html("");
            var list = data.page.list;
            var html_ = "";
            for (var i = 0; i < list.length; i++) {
                html_ += "<tr><td>" + list[i].user_id + "</td><td>" + list[i].userName + "</td>";
                html_ += "<td>" + list[i].mobilephone + "</td><td>" + list[i].alipay + "</td><td>" + list[i].money + "</td>";
                html_ += "<td>" + list[i].money_before + "</td><td>" + list[i].money_after + "</td><td>" + list[i].create_date + "</td>";
                var status = list[i].status;
                if (status == 1) {
                    html_ += "<td>" + list[i].check_date + "</td>";
                    html_ += "<td>" + list[i].check_name + "</td>";
                    html_ += "<td>" + list[i].alipay_order_id + "</td>";
                    html_ += "<td><span style='color: green;'>已打款</span></td>";
                    html_ += "<td> - </td></tr>";
                } else if(status == 2) {
                    html_ += "<td> - </td>";
                    html_ += "<td> - </td>";
                    html_ += "<td> - </td>";
                    html_ += "<td><span style='color: red;'>打款失败</span></td>";
                    html_ += "<td><div class='hidden-sm hidden-xs btn-group'>";
                    html_ += "<button class='btn btn-xs btn-info' title='退回余额' onclick='showBackMoneyConfirm(" + list[i].id +")'><i class='icon-refresh bigger-120'></i>退回余额</button>";
                    html_ += "</td></tr>";
                } else if(status==3) {
                    html_ += "<td>" + list[i].check_date + "</td>";
                    html_ += "<td>" + list[i].check_name + "</td>";
                    html_ += "<td> - </td>";
                    html_ += "<td><span style='color: red;'>已退回余额</span></td>";
                    html_ += "<td> - </td></tr>";
                } else {
                    html_ += "<td> - </td>";
                    html_ += "<td> - </td>";
                    html_ += "<td> - </td>";
                    html_ += "<td><span style='color: red;'>未打款</span></td>";
                    html_ += "<td><div class='hidden-sm hidden-xs btn-group'>";
                    html_ += "<button class='btn btn-xs btn-info' title='确认打款' onclick='settlement(" + list[i].id + ",\"" + list[i].userName + "\",\"" + list[i].mobilephone + "\",\"" + list[i].alipay + "\",\""+list[i].money + "\")'><i class='icon-money bigger-120'></i>确认打款</button>";
                    html_ += "</td></tr>";
                }
            }
            $loadData.html(html_);
            pageValue(data);
            pageData();
            $("#btn-load").button("reset");
        });
    }

    loadData();

    function confirmTx() {
        var para = {
            id: $("#id").val(),
            alipay_order_id: $("#alipay_order_id").val(),
            remark: $("#remark").val(),
            status : $("#txStatus input:radio[name='status']:checked").val(),
        };
        loadGetServer('/manager/money/confirmTx', para, function (data) {
            if (data.code != 0) {
                alert(data.msg);
            } else {
                alert('操作成功')
                $('#txModal').modal('hide');
            }
            loadData();
        });
    }

    function backMoney(id) {
        var para = {
            id: id
        };
        loadGetServer('/manager/money/backMoney', para, function (data) {
            if (data.code != 0) {
                alert(data.msg);
            } else {
                alert('操作成功')
                $('#txModal').modal('hide');
            }
            loadData();
        });
    }

    function settlement(id,userName,phone,alipay,money) {
        $("#txForm")[0].reset();
        $("#id").val(id);
        $("#userName").val(userName);
        $("#phone").val(phone);
        $("#alipay").val(alipay);
        $("#money").val(money);
        $('#txModal').modal('show');
    }

    function showBackMoneyConfirm(id) {
        var r = confirm("是否确定退回用户账户余额？");
        if (r == true) {
            backMoney(id);
        }
    }
</script>